package com.fs.system.student.controller;

import com.fs.system.common.ResponseData;
import com.fs.system.student.domain.Student;
import com.fs.system.student.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 修改学生信息
     * @param student
     * @return
     */
    @PutMapping("/collegeAdminStudent/edit")
    public ResponseData edit(@RequestBody Student student){
        return studentService.updateStudentInfo(student);
    }

    /**
     * 获取学生信息,可模糊查询
     * @return
     */
    @GetMapping("/collegeAdminStudent/list")
    public ResponseData list( Student student){
        return studentService.getStudentInfo(student);
    }

    /**
     * 逻辑删除学生信息，修改isDeleted字段为true
     * @param stuId
     * @param updateBy
     * @return
     */
    @PutMapping("/collegeAdminStudent/delete")
    public ResponseData delete(@RequestParam Long stuId,@RequestParam String updateBy){
        System.out.println(stuId+updateBy);
        return studentService.deleteStudent(stuId,updateBy);
    }

    /**
     * 批量逻辑删除学生信息
     * @param ids
     * @param updateBy
     * @return
     */
    @PutMapping("/collegeAdminStudent/deleteBatch/{updateBy}")
    public ResponseData deleteBatch(@PathVariable String updateBy,@RequestBody List<Long> ids){
        System.out.println(ids);
        return studentService.deleteBatch(ids,updateBy);
    }

    /**
     * 分页查询学生信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/collegeAdminStudent/selectPage")
    public ResponseData selectPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Student student){
        PageInfo<Student> studentPageInfo = studentService.selectPage(pageNum, pageSize, student);
        return new ResponseData("200","查询成功",studentPageInfo);
    }

    /**
     * 添加学生信息
     * @param student
     * @return
     */
    @PostMapping("/collegeAdminStudent/addOneStudent")
    public ResponseData addOneStudent(@RequestBody Student student){
        return studentService.addOneStudent(student);
    }

}

